/**
 * 
 */
package jm.lib.collections.map;

import java.io.Serializable;
import java.util.Map.Entry;

/**
 * 
 * 
 * @author Jiming Liu
 *
 */
@SuppressWarnings("serial")
public class SimpleMapEntry<K,V> implements Entry<K,V>, Serializable{
	private K key;
	private V value;
	
	public SimpleMapEntry(K k) {
		key = k;
	}

	public SimpleMapEntry(K k, V v) {
		key = k;
		value = v;
	}

	public K getKey() {
		return key;
	}
	
	public V getValue() {
		return value;
	}

	public V setValue(V v) {
		V old = value;
		value = v;
		return old;
	}

	/**
	 * Returns <code>true</code> if this <code>SimpleMapEntry</code> is the same as the o argument.
	 *
	 * @return <code>true</code> if this <code>SimpleMapEntry</code> is the same as the o argument.
	 */
	public boolean equals(Object o) {
		if (this == o) {
			return true;
		}
		if (o == null) {
			return false;
		}
		if (o.getClass() != getClass()) {
			return false;
		}
		SimpleMapEntry castedObj = (SimpleMapEntry) o;
		return ((this.key == null ? castedObj.key == null : this.key
			.equals(castedObj.key)) && (this.value == null
			? castedObj.value == null
			: this.value.equals(castedObj.value)));
	}

	/**
	 * Override hashCode.
	 *
	 * @return the Objects hashcode.
	 */
	public int hashCode() {
		int hashCode = 37;
		hashCode = 31 * hashCode + (key == null ? 0 : key.hashCode());
		hashCode = 31 * hashCode + (value == null ? 0 : value.hashCode());
		return hashCode;
	}

	/**
	 * @generated by CodeSugar http://sourceforge.net/projects/codesugar */
	
	public String toString() {
		StringBuilder buffer = new StringBuilder();
		buffer.append("[SimpleMapEntry:");
		buffer.append(" key: ");
		buffer.append(key);
		buffer.append(" value: ");
		buffer.append(value);
		buffer.append("]");
		return buffer.toString();
	}

	public Object clone() {
		SimpleMapEntry<K,V> inst = new SimpleMapEntry<K,V>(key);
		inst.value = this.value;
		return inst;
	}

}
